home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Headers / misckit / MiscThreadedObject.h < prev    next >
Encoding:
Text File  |  1994-12-09  |  2.0 KB  |  68 lines

  1. /*
  2.  *     File:     MiscThreadedObject.h
  3.  *  Version:    1.0
  4.  *   Author:    Steve Quirk
  5.  *  Summary:    Provides basic threading mechanism to Object
  6.  *
  7.  *    Revision History:
  8.  *        Nov 1994    steveq    created
  9.  *
  10.  *    Copyright 1994    Steve Quirk    steveq@telerate.com
  11.  *
  12.  *    A threaded object can run in it's own thread.  Simply send a 
  13.  *    runInNewThread message to the instance & a thread will be created
  14.  *    and the instance's 'run' method will be invoked.  The thread will
  15.  *    be destroyed when the run method returns.
  16.  *    To be useful, a subclass must override the run method - this 
  17.  *    implementation simply returns self.
  18.  *
  19.  *    By default, the instance is sent a 'free' message after the 'run' method
  20.  *    returns. Override this behaviour by sending 'freeAfterRun:NO'. Of course,
  21.  *    don't call 'free' until after run returns.
  22.  *
  23.  *    To aid debugging, the name of the thread will be whatever is returned
  24.  *    by [self name].  Override -name if you want to customize that.
  25.  *
  26.  */
  27. #import    <objc/Object.h>
  28. #import <mach/cthreads.h>
  29. #import <mach/thread_info.h>
  30.  
  31. @interface    MiscThreadedObject:Object
  32. {
  33.     cthread_t objThread;
  34.     thread_info_t    info;
  35.     thread_info_t    schedInfo;
  36.     BOOL    freeOnReturnFromRun;        /* default = YES */
  37. }
  38. /*
  39.  *    get/set thread count limit for task
  40.  */
  41. + (int)getThreadLimit;
  42. + (void)setThreadLimit:(int)newLimit;
  43. + (int)errno;
  44.  
  45. - (BOOL)freeAfterRun;
  46. - freeAfterRun:(BOOL)yesOrNo;            /* NO => keep object after thread exits */
  47.  
  48. /*
  49.  *    run methods:
  50.  */
  51. - run;                /* override this to do something useful */
  52. - runInNewThread;    /* spawns new thread (which calls run) & returns self */
  53. - fork;                /* spawns new thread but doesn't detach */
  54. - (any_t)join;        /* suspends caller until receiver exits thread */
  55.  
  56. - (thread_info_t)threadInfo;        /* returns basic thread information    */
  57. - (thread_info_t)threadSchedInfo;    /* returns scheduling thread information */
  58.  
  59. /*
  60.  *    suspend/resume a thread:
  61.  */
  62. - suspend;            /* suspend's the receiver's thread */
  63. - resume;            /* undoes a suspend */
  64. - abort;            /* aborts a system call the receiver may be executing */
  65. - switchTo;            /* causes a context switch into the receivers thread */
  66.  
  67. @end
  68.